#ifndef _RBTREE_H
#define _RBTREE_H

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

enum REDORBLACK
{
    RBT_RED,
    RBT_BLACK
};

enum CHILDPOS
{
    RBT_NULL,
    RBT_LEFT,
    RBT_RIGHT
    
};

typedef struct RBTreeNode
{
    unsigned short color;//红-0  黑-1
    void *pkey;
    void *pvalue;
    struct RBTreeNode *pParentNode;
    struct RBTreeNode *pLChild;
    struct RBTreeNode *pRChild;
}RBTreeNode;

extern RBTreeNode* NIL;

void rbtree_initNIL();
int rbtree_insert_node(RBTreeNode **root,void *key,void *value);
RBTreeNode *rbtree_search(RBTreeNode *root,void *key);
int rbtree_delete_node(RBTreeNode **root,RBTreeNode *node);

typedef int (*rbtree_compare)(void *key1,void *key2);
extern rbtree_compare g_compare;

#endif